<?php 
	Class Flightprice extends CI_Controller{
		public function __construct(){
			parent::__construct();
			$this->load->model('model_flightprice');	
			$this->load->model('model_flight');	
		}	
		
		public function index(){
			if(isset($_GET['flightid'])){
				$data['flight']=$this->model_flight->getdata(intval($_GET['flightid']));	
				$data['data']=$this->model_flightprice->getallbyid(intval($_GET['flightid']));
			}
			
			$data['template']='flight/flightprice';
			$this->load->view('layout',$data);
		}
		
		public function edit(){
			if(isset($_GET['id'])){				
				$data['detail']	=$this->model_flightprice->getdata(intval($_GET['id']));
			}else $data['detail']=NULL;
			$data['flight']=$this->model_flight->getdata(intval($_GET['flightid']));
			$data['template']='flight/flightprice_edit';
			$this->load->view('layout',$data);
		}
		
		public function insert(){
			$data['priceforadult']=$_POST['priceforadult'];	
			$data['priceforchild']=$_POST['priceforchild'];
			$data['datefrom']=date("Y-m-d",strtotime($_POST['datefrom']));
			$data['dateto']=date("Y-m-d",strtotime($_POST['dateto']));
			$data['status']=$_POST['status'];
			$data['flightid']=$_GET['flightid'];
			$this->model_flightprice->add($data);
			header('Location: '.base_url().'admin/flightprice/index?flightid='.$_GET['flightid']);
		}
		
		public function update(){
			if(isset($_GET["id"])){
				$data['priceforadult']=$_POST['priceforadult'];	
				$data['priceforchild']=$_POST['priceforchild'];
				$data['datefrom']=date("Y-m-d",strtotime($_POST['datefrom']));
				$data['dateto']=date("Y-m-d",strtotime($_POST['dateto']));
				$data['status']=$_POST['status'];
				$data['flightid']=$_GET['flightid'];
				$this->model_flightprice->update($data,intval($_GET['id']));
				header('Location: '.base_url().'admin/flightprice/index?flightid='.$_GET['flightid']);
			}	
		}
		
		public function delete(){
			if(isset($_GET["id"])){
				$this->model_flightprice->del(intval($_GET['id']));	
				header('Location: '.base_url().'admin/flightprice/index?flightid='.$_GET['flightid']);
			}	
		}
		
		public function changestatus(){		
			if(isset($_GET["status"])){
				$data['status']=intval($_GET['status']);
				$this->model_flightprice->update($data,intval($_GET["id"]));
				header('Location: '.base_url().'admin/flightprice/index?flightid='.$_GET['flightid']);
			}
		}
	}
?>